package com.un.ebs.core.util;

import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;

import java.util.Optional;

/**
 * @author liubo
 * @email liubocs@163.com
 * @date 2020/4/22 23:15
 */
public class TableUtils {

    public static String getFieldName(Class<?> cls, String propertyName) {
        TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
        Optional<String> ret = tableInfo.getFieldList().stream().filter(s -> propertyName.equals(s.getProperty())).map(s -> s.getColumn()).findFirst();
        if (ret.isPresent()) {
            return ret.get();
        } else {
            return null;
        }
    }
}
